<!--#include file="functions.asp" -->
<%
'set cn=Server.CreateObject("ADODB.Connection")
'cn.Open "MP2ENTTEST2", "MP2", "MP2"
dim sql

'update exireg
If (request("MyInvoice") = "Y") then
    sql = "UPDATE EXILVOHEADER SET "
	sql = sql & " INVVER = '" & request("reqEndUser") & "',"
	sql = sql & " INVAPPR = '" & request("reqAuthorised") & "',"
	if (request("TrType") = "Route") then
	sql = sql & " ROUTEUSER = '" & request("reqEndUser") & "',"
	sql = sql & " STATUS='ROUTED',"
	elseif (request("TrType") = "Verify") then
	sql = sql & " ROUTEUSER = '" & request("reqAuthorised") & "',"
	sql = sql & " STATUS='ROUTED',"
	sql = sql & " INVVERDATE=GETDATE(),"
	elseif (request("TrType") = "Approve") then
	sql = sql & " ROUTEUSER = 'FINANCE',"
	sql = sql & " STATUS='APPROVED',"
	sql = sql & " INVAPPRDATE=GETDATE(),"
	end if
	if (request("Comments")<>"") then
      txComments = dblq(request("Comments1")) & Chr(13)
	  txComments = txComments & ">" & UCase(UsrFullname) & ":  " 
	  txComments = txComments & dblq(request("Comments"))
	  sql = sql & " COMMENTS= '" & txComments & "',"
    end if
	'sql = sql & " COMMENTS='" & dblq(request("Comments")) & "',"
	sql = sql & " ROUTEDATE=GETDATE()" 
	sql = sql & " WHERE LVONUM='" & request("seqnum2") & "'"
else
  	sql = "UPDATE EXILVOHEADER SET "
	if (Request("Route")="EU") then
	 sql = sql & " INVVER = '" & request("reqEndUser") & "',"
	else
	 sql = sql & " UCCODE = '" & request("reqEndUser") & "',"
	end if
	sql = sql & " ROUTEUSER = '" & request("reqEndUser") & "',"
	'sql = sql & " INVAPPR = '" & request("reqAuthorised") & "',"
	sql = sql & " STATUS='ROUTED',"
	sql = sql & " REFERENCEDOC='" & request("reqSupDoc") & "',"
	if (request("Comments")<>"") then
      txComments = dblq(request("Comments1")) & Chr(13)
	  txComments = txComments & ">" & UCase(UsrFullname) & ":  " 
	  txComments = txComments & dblq(request("Comments"))
	  sql = sql & " COMMENTS= '" & txComments & "',"
    end if
	'sql = sql & " COMMENTS='" & dblq(request("Comments")) & "',"
	'sql = sql & " UPDATEUSER='" & usrName & "',"
	sql = sql & " ROUTEDATE=GETDATE()" 
	sql = sql & " WHERE LVONUM='" & request("seqnum2") & "'"
end if

	cn.execute(sql)

'update exihist

'create email notification
if (request("TrType") = "Route") then
    sRecipients = GetLoginName(request("reqEndUser"))
end if
if (request("TrType") = "Verify") then
    sRecipients = GetLoginName(request("reqAuthorised"))
end if
    sDomainName = "@Premier-oil.com"
	EmailSubject = "Electronic Invoice Approval "  
	EmailBody = "<HTML><HEAD><TITLE></TITLE></HEAD><BODY>"
	EmailBody = EmailBody & "<FONT face=Arial size=2>Dear sir/madame </font><BR><BR>"
	EmailBody = EmailBody & "<FONT face=Arial size=2>Please find Invoice for your review: </font><BR><BR>"
	EmailBody = EmailBody & "<FONT face=Arial size=2>Vendor Name: " & request("VendorName") & "</font><BR>"
	EmailBody = EmailBody & "<FONT face=Arial size=2>Invoice No: " & request("InvoiceNo") & "</font><BR>"
	EmailBody = EmailBody & "<FONT face=Arial size=2><b><a href='" & theURL & "/my_InvoiceLVO.asp?LVONum=" & request("seqnum2") &"'>Click here for Invoice detail</a></b></font><BR><BR>"
	EmailBody = EmailBody & "<FONT face=Arial size=2>Thank you for your kind cooperation </font><BR><BR>"
	EmailBody = EmailBody & "<FONT face=Arial size=2><b>Finance Department </b></font>"
	EmailBody = EmailBody & "</BODY></HTML>"

    dim MyBody
	MyBody = ReformatText(EmailBody)
	SendCDOEmail sRecipients, "", "", "Finance_Department", EmailSubject, MyBody


'back to approval page
If (request("MyInvoice") = "Y") then
response.redirect "My_InvoiceLVO.asp?LVOnum="& request("seqnum2")
else
response.redirect "Inv_DetailLVO.asp?LVOnum="& request("seqnum2")& "&Order=" & request("order")& "&Sort=" & request("sort")
end if

%>
